package com.meaningful.design_pattern.composite_pattern;

import java.util.ArrayList;
import java.util.List;

public class Province implements PopulationNode {

    private final String name;

    private List<City> cityList = new ArrayList<City>();

    public Province(String name) {
        this.name = name;
    }

    public Province(String name, List<City> cityList) {
        this.name = name;
        this.cityList = cityList;
    }

    public void addCity(City city) {
        cityList.add(city);
    }

    @Override
    public int computePopulation() {
        return cityList.stream().mapToInt(City::computePopulation).sum();
    }

}
